package com.nit.lab.vote.dto.basic;

import org.springframework.util.DigestUtils;

import java.util.Random;
import java.util.UUID;

public class UserDTO {
    private Long key;
    private Long userId;
    private Long projectId;
    private String userName;
    private Integer roleId;
    private String phone;
    private String password;
    private String original;

    public UserDTO() {
    }

    public UserDTO(Long key, Long userId, String userName, Integer roleId, String phone, String password, String original) {
        this.key = key;
        this.userId = userId;
        this.userName = userName;
        this.roleId = roleId;
        this.phone = phone;
        this.password = password;
        this.original = original;
    }
    public Long getKey() {
        return key;
    }

    public void setKey(Long key) {
        this.key = key;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public Integer getRoleId() {
        return roleId;
    }

    public void setRoleId(Integer roleId) {
        this.roleId = roleId;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getOriginal() {
        return original;
    }

    public void setOriginal(String original) {
        this.original = original;
    }

    public Long getProjectId() {
        return projectId;
    }

    public void setProjectId(Long projectId) {
        this.projectId = projectId;
    }

    public void createRandomPwd() {
        final String charSet = "0123456789";
        StringBuilder pw = new StringBuilder();
        Random random = new Random(System.currentTimeMillis());
        int pwLen = 6;
        for (int i = 0; i < pwLen; i++) {
            pw.append(charSet.charAt(random.nextInt(charSet.length())));
        }
        original = pw.toString();
        password = DigestUtils.md5DigestAsHex(original.getBytes());
    }

    public static void main(String[] args) {
        UserDTO userDTO = new UserDTO();
        for (int i = 0; i < 2; i++) {
            userDTO.createRandomPwd();
            System.out.println(userDTO.original);
            System.out.println(userDTO.password);
        }
    }
}
